package com.kailu.servicelist.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kailu.servicelist.form.ServiceList;

@Repository
public class ServiceListDAOImpl implements ServiceListDAO {

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void addServiceList(ServiceList serviceList) {
		sessionFactory.getCurrentSession().save(serviceList);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ServiceList> getServiceList() {
		return sessionFactory.getCurrentSession().createQuery("from service").list();
	}

	@Override
	public void removeServiceList(int Id) {
		ServiceList sl = (ServiceList) sessionFactory.getCurrentSession().load(ServiceList.class, Id);
        if (null != sl) {
            sessionFactory.getCurrentSession().delete(sl);
        }
	}

	@Override
	public void updateServiceList(ServiceList serviceList) {
		sessionFactory.getCurrentSession().update(serviceList);
	}

}
